package com.bilibili.server.controller;

import com.bilibili.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author HuangRongFu
 * 2021/11/15 星期一10:11 下午
 */

@RestController
@RequestMapping("/user")
@Slf4j
public class LoginController {

    //要调用发送验证码服务
    @Autowired
    private UserService userService;

    /**
     * 登录功能  通过手机号码发送验证码登录
     *
     * @param: paramMap
     * @Return: ResponseEntity
     */
    @RequestMapping("/login")  //返回http响应  ResponseEntity spring封装的 http状态
    public ResponseEntity login(@RequestBody Map<String, String> paramMap) {

        //调用service发送验证码
        userService.sendValidateCode(paramMap);

        //前端需要的返回值为空 我们只要返回是否成功 ResponseEntity.ok 状态200  表示成功
        return ResponseEntity.ok(null);
    }


    /**
     * 登录验证码的校验
     *
     * @param: paramMap
     * @Return: ResponseEntity
     */
    @RequestMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map<String, String> paramMap) {

        Map<String, Object> resultMap = userService.loginVerification(paramMap);

        return ResponseEntity.ok(resultMap);
    }

}
